/********************************************************************************
Title: Data Preparation for DRC Sample
* this is done remotely -> ask Maarten
********************************************************************************/


use "${raw}/drc/drc_desc", clear
sort pid date
collapse (firstnm) age ses female, by(pid)
tempfile desc
save `desc'

use "${raw}/drc/drc", clear
bysort pid (date): gen first = _n == 1
loc ref first == 1

merge m:1 pid using `desc'

tostring pid, gen(hhid)

*			0.2		Month
*-------------------------------------------------------------------------------
replace date = . if date < mdy(1,1,2018)
gen month = month(date) +4 + 12*year(date) - 12*2019
tab month

*-------------------------------------------------------------------------------
*			1. Generating Variable Lists
*-------------------------------------------------------------------------------
gl hscl "tr1_ tr2_ tr3_ tr4_ tr5_ tr6_ tr7_ tr8_ tr10_ tr11_ tr12_ tr13_ tr14_ tr15_ tr16_ tr17_ tr18_ tr19_ tr20_ tr21_ tr22_ tr23_ tr24_ tr25_"
gl vars $hscl
gl depression $hscl



*-------------------------------------------------------------------------------
*			2. Generating HSCL-25 score
*-------------------------------------------------------------------------------

egen nmissing = rowmiss($hscl) 

egen hscl_score = rmean($hscl) if nmissing<4 // at least 22 out of 25 should be answered to create consistent score.

sum hscl_score if `ref'
gen ___depression_nw = (hscl_score - `r(mean)')/`r(sd)'  //ATTN: Use this for all countries


foreach var in $vars { //ATTN Duplicate in other ctry
*	gen g`var' =`var'-1
	replace `var' = -1*`var'
}


corr $vars if `ref'

foreach var in  $vars { //ATTN Duplicate in other ctry
	sum `var' if `ref'
	replace `var' = (`var' - `r(mean)')/`r(sd)'
	gen swt_`var' = `var'
}



*-------------------------------------------------------------------------------
*          Factor Analysis
*-------------------------------------------------------------------------------

factor $depression if `ref', ipf factor(1) //ATTN Duplicate in other ctry
predict ___depression_fw

icw_index($depression), gen(___depression_icw) //ATTN Duplicate in other ctry


* Checking Cronbach's alpha
*Validated tool HSCL-25
alpha tr1_ tr2_ tr3_ tr4_ tr5_ tr6_ tr7_ tr8_ tr10_ tr11_ tr12_ tr13_ tr14_ tr15_ tr16_ tr17_ tr18_ tr19_ tr20_ tr21_ tr22_ tr23_ tr24_ tr25_ // Scale reliability coefficient= 0.943
*Weighted depression score
alpha tr1_ tr2_ tr3_ tr4_ tr5_ tr6_ tr7_ tr8_ tr10_ tr11_ tr12_ tr13_ tr14_ tr15_  // Scale reliability coefficient= 0.901



reg ___depression_nw ses
